package com.cvo.scrumtoolkit.client.controller;

import java.lang.reflect.InvocationTargetException;

import com.cvo.scrumtoolkit.client.pannels.BacklogPanel;
import com.cvo.scrumtoolkit.client.pannels.DefaultPanel;
import com.cvo.scrumtoolkit.client.pannels.SprintOverviewPanel;



import com.cvo.scrumtoolkit.client.pannels.HomePanel;

import com.google.gwt.user.client.ui.Composite;

/**
 * 
 * @author Ricardo Cappelle
 *
 * This class is a factory that is able to create the right kind of widget
 * according to the specified widget type
 *
 */
public class CompositeFactory {
	private static CompositeFactory compositeFactory;
	

    private CompositeFactory()
    {
        // no private method because of singleton
    }

    /**
     * Singleton controller
     * @return A singleton controller
     */
    public static CompositeFactory getCompositeFactory()
    {
      if (compositeFactory == null){
    	  compositeFactory = new CompositeFactory();
    	  return compositeFactory;
      } else {
    	  return compositeFactory;
      }
    }

    /**
     * Creates the right kind of Composite according to view type definition
     * @param view The view type
     * @return	The view that was created
     * @throws ClassNotFoundException 
     * @throws InvocationTargetException 
     * @throws IllegalAccessException 
     * @throws InstantiationException 
     * @throws NoSuchMethodException 
     * @throws IllegalArgumentException 
     * @throws SecurityException 
     */
	public Composite createView(Navigator navigatorData) {
		View selectedView = navigatorData.getView();
		
		
		switch (selectedView) {
		case HOME:
			return new HomePanel();		
		case PRODUCTBACKLOG: 
			return new BacklogPanel();
		case SPRINTBACKLOG: 
			return new SprintOverviewPanel();		
		case BURNDOWNCHART: 
			return new DefaultPanel();	
		case SCRUMBOARD: 
			return new DefaultPanel();
		
		default:
			return new DefaultPanel();		
		}
	}
	



}
